import { createRouter, createWebHashHistory } from "vue-router";
import Login from "@/pages/login.vue";
import layout from "@/layouts/layout.vue";
import { useSystemStore } from "../store";

const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: '/',
            component: layout,
            children: [
                {
                    path: '/patient',
                    name: 'Patient',
                    component: () => import('@/pages/patient/patient.vue')
                },
                {
                    path: '/save-patient',
                    name: 'SavePatient',
                    component: () => import('@/pages/patient/save.vue')
                },
                {
                    path: '/patient-detail',
                    name: 'PatientDetail',
                    component: () => import('@/pages/patient/detail.vue')
                },
                {
                    path: '/inspect',
                    name: 'inspect',
                    component: () => import('@/pages/inspect/inspect.vue')
                },
                {
                    path: '/medicine',
                    name: 'Medicine',
                    component: () => import('@/pages/medicine/medicine.vue')
                },
                {
                    path: '/adr',
                    name: 'Adr',
                    component: () => import('@/pages/adr/adr.vue')
                }
            ]
        },
        {
            path: '/login',
            name: 'Login',
            component: Login
        },
    ]
});

router.beforeEach((to, from, next) => {
    const systemStore = useSystemStore();
    systemStore.$patch({activeRouter: [to.path]});
    // TODO 权限校验
    next();
});

export default router;